from sync.models import *
from django.conf import settings
from django.shortcuts import render_to_response
from django.core import serializers
from django.http import HttpResponse

# ==============
# = Server API =
# ==============
def changesets(request,format=None):
    """
    Pulls all the changesets that are local to the syncroot.
    """
    changesets = ChangeSet.objects.filter(syncroot=settings.LOCAL_SYNCROOT).filter(closed__isnull=False) # grabs local, committed changesets
    if format is not None:
        serializer = serializers.get_serializer(format)()
        response = HttpResponse()
        serializer.serialize(changesets,stream=response)
        return response
    else:
        return render_to_response('changesets.html',{'changesets':changesets})

def push(request,format):
    """
    Pushes changes to this server.
    """
    pass # TODO

def pull(request,format):
    """
    Pulls changes from this server.
    """
    pass # TODO
    